package com.mgface.springdata.repository;

import com.mgface.springdata.entity.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project springdataCollection
 * @create 2018-08-17 10:18
 **/
@Repository
public interface StudentRepository extends JpaRepository<Student,Long> {
    List<Student> findByNameOrderByIdAsc(String sName);
    Page<Student> findAllBy(Pageable pageable);
    @Query(value = "select * from student s where s.id<=?1",nativeQuery = true)
    List<Student> myQuery(long id);
    @Query(value = "select * from student \n#pageable\n ",countQuery = "select count(1) from student",nativeQuery = true)
    Page<Student> myQueryAll(Pageable pageable);
    @Modifying
    @Query("update Student s set s.name=:name where s.id=:id")
    void myUpdate(@Param("name") String name,@Param("id") long id);
    @Modifying
    @Query(value = "delete from Student where id =:id ",nativeQuery = false)
    void myDelete(@Param("id") long id);
}
